package com.sys.orders.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.pojo.ApiResponseEnum;
import com.sys.common.service.BaseServiceImpl;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.orders.dao.IAOrdersDao;
import com.sys.orders.service.IOrdersDbService;
import com.sys.orders.service.IOrdersOperService;

/**
 * Service实现类(订单代码)
 * 
 * @author 朱明宇
 */
@Service("ordersOperService")
public class OrdersOperServiceImplay extends BaseServiceImpl implements IOrdersOperService
{
	@Resource
	private IOrdersDbService ordersDbService;
	@Resource
	private IAOrdersDao ordersDao;
	
	@Override
	public ApiResponse<Map<String, Object>> findStatOrdersListMapService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		ApiResponse<Map<String, Object>> apiResponse = new ApiResponse<Map<String, Object>>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<Map<String, Object>> demoOrdersList = Collections.EMPTY_LIST;

		Map<String, List<Map<String, Object>>> dataList = new HashMap<String, List<Map<String, Object>>>();
		/* 设置分页相关信息 */
		if(pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
			demoOrdersList = this.ordersDao.statListMap(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		}else
		{
			demoOrdersList = this.ordersDao.statListMap(condMap);
		}
		
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoOrdersList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoOrdersList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
}
